//编辑模态框
import React, { Component } from "react";
import { connect } from "dva";

import {
    Form,
    Radio,
    Modal,
    Table,
    Select,
    Cascader,
    DatePicker,
    Dropdown,
    Button,
    menu,
    Icon,
    message,
    Pagination,
    Input,
    TimePicker
} from "antd";
import moment from "moment";
import {CheckEdit} from "../../../services/redmoe";
const { TextArea } = Input;


//form表单套件
const { MonthPicker, RangePicker, WeekPicker } = DatePicker;


    class Checkmodal extends Component {

        //日期
        DatePicker = (data,datastring) => {
            console.log(data,datastring)
                 
           
        }

                  //普通输入框
        onShowChange = (type, e) => {
            let value = e.target.value;
            if(value == '') {
                this.setState({
                    [type]:null
                })
            }
            if(value != '') {
                this.setState({
                    [type]: value
                })
            }
            
            console.log("type:", value);
        }

          state={
              useDate:'',
              useNaturalGas:'',
              useElectric:'',
              useWater:'',
            row:""
          }
          componentWillMount(){
              this.setState({
                  row:this.props.row
              })
          }

          save = () => {
              if(this.state.useDate == '') {
                  this.setState({
                      useDate:moment(this.props.row.useDate).format('YYYY-MM-DD')
                  })
              }

              if(this.state.useNaturalGas == '') {
                  this.setState({
                    useNaturalGas:this.props.row.useNaturalGas
                  })
              }

              if(this.state.useElectric == '') {
                this.setState({
                    useElectric:this.props.row.useElectric
                })
            }

            if(this.state.useWater == '') {
                this.setState({
                    useWater:this.props.row.useWater
                })
            }

            setTimeout( () => {
                let data = {
                    id:this.props.row.id,
                    useDate:this.state.useDate,
                    useNaturalGas:this.state.useNaturalGas,
                    useElectric:this.state.useElectric,
                    useWater:this.state.useWater,
                }
                CheckEdit({...data}).then( data => {
                    console.log(data)
                    if(data.data.rc == 0) {
                        this.props.editcg('1')
                    }
                })

            },500)
          }



        render() {
            const { visible, onCancel, onCreate, form ,text,row} = this.props;
            console.log(this.props.row)

            return (
              <Modal
                 
                  visible={visible}
                  title="编辑记录"
                  okText="保存"
                  cancelText="关闭"
                  onCancel={onCancel}
                  onOk={this.save}
                 
              >
              日期 <DatePicker defaultValue={moment(moment(row.useDate).format('YYYY-MM-DD'), 'YYYY-MM-DD')} value={this.state.useDate == ''?moment(moment(row.useDate).format('YYYY-MM-DD'), 'YYYY-MM-DD'):moment(this.state.useDate, 'YYYY-MM-DD')} onChange={this.DatePicker.bind(this.DatePicker)}/>
              燃气抄表值/Nm³ : <Input style={{width:170,marginTop:10}} type="textarea"  size="small" defaultValue={row.useNaturalGas} value={this.state.useNaturalGas == ''?row.useNaturalGas:this.state.useNaturalGas} onChange={this.onShowChange.bind(this, 'useNaturalGas')}/> <br/>
              电耗抄表值 : <Input style={{width:170,marginTop:10}} type="textarea" size="small" defaultValue={row.useElectric} value={this.state.useElectric == ''?row.useElectric:this.state.useElectric} onChange={this.onShowChange.bind(this, 'useElectric')}/><br/>
              水耗抄表值 : <Input style={{width:170,marginTop:10}} type="textarea" size="small" defaultValue={row.useWater} value={this.state.useWater == ''?row.useWater:this.state.useWater} onChange={this.onShowChange.bind(this, 'useWater')}/><br/>
          
             
                
              </Modal>
          )
           }
           
        }



export default connect()(Checkmodal);
